// To do: Remove all rendering from here !

using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace SpaceWolf.GameLogic
{
    
    public class Galaxy
    {
        #region Variables
        public List<Planet> arPlanets = new List<Planet>();
        public int iTotalPlanets=20;
        private galaxy_seed glx;

        public galaxy_seed CurrentGalaxySeed
        {
            get
            {
                return this.glx;
            }
        }

        public int JumpToPlanet;

        #endregion

        public Galaxy(byte Galaxy)
        {
            glx = new galaxy_seed(0x4a, 0x5a, 0x48, 0x02, 0x53, 0xb7);
            BuidPlanets();
        }

        public static galaxy_seed waggle_galaxy(galaxy_seed glx_ptr)
        {
            int x;
            int y;

            x = glx_ptr.a + glx_ptr.c;
            y = glx_ptr.b + glx_ptr.d;


            if (x > 0xFF)
                y++;

            x &= 0xFF;
            y &= 0xFF;

            glx_ptr.a = glx_ptr.c;
            glx_ptr.b = glx_ptr.d;
            glx_ptr.c = glx_ptr.e;
            glx_ptr.d = glx_ptr.f;

            x += glx_ptr.c;
            y += glx_ptr.d;


            if (x > 0xFF)
                y++;

            x &= 0xFF;
            y &= 0xFF;

            glx_ptr.e = Convert.ToByte(x);
            glx_ptr.f = Convert.ToByte(y);

            return glx_ptr;
        }

        private void BuidPlanets()
        {
            for (byte iCounter = 0; iCounter < iTotalPlanets; iCounter++)
            {
                Planet planet = new Planet(glx);
                arPlanets.Add(planet);

                glx = waggle_galaxy(glx);
                glx = waggle_galaxy(glx);
                glx = waggle_galaxy(glx);
                glx = waggle_galaxy(glx);
            }
        }

        public void PlanetDescription(int iPlanetNum)
        {
            string str = string.Empty;

            str=string.Format("Data on {0}", arPlanets[iPlanetNum].Name);
            Helper.Fonts.WriteText(Convert.ToInt32((BaseGame.Width / 1280.0f) * 85), Convert.ToInt32((BaseGame.Height / 1024.0f) * 50), str, Color.Green);

            //show_distance(42, docked_planet, hyperspace_planet);
            
            planet_data techData=arPlanets[iPlanetNum].TechData;

            str = string.Format("Economy:{0:s}", techData.economy.ToString().Replace("_", " "));
            Helper.Fonts.WriteText(386, 130, str);

            str = string.Format("Government:{0:s}", techData.government.ToString().Replace("_", " "));
            Helper.Fonts.WriteText(386, 150, str);

            str = string.Format("Tech.Level:{0:d}", techData.techlevel + 1);
            Helper.Fonts.WriteText(386, 170, str);

            str = string.Format("Population:{0:d}.{1:d} Billion", techData.population / 10, techData.population % 10);
            Helper.Fonts.WriteText(386, 190, str);

            str = string.Format("Gross Productivity:{0:d} M CR", techData.productivity);
            Helper.Fonts.WriteText(386, 210, str);

            str = string.Format("Average Radius:{0:d} km", techData.radius);
            Helper.Fonts.WriteText(386, 230, str);

            str = arPlanets[iPlanetNum].Inhabitants;
            Helper.Fonts.WriteText(56, 450, str);

            Helper.Fonts.WriteText(56, 470,arPlanets[iPlanetNum].Description);
        }
    }
}
